package com.wyq.new_springboot.util.result;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 接口返回结果类
 * 使用builder插件
 * @author wyq on 2021/3/28.
 */
@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
public class Result {
        private int code;
        private String message;
        private Object data;
        public static final class ResultBuilder {
                private int code;
                private String message;
                private Object data;

                private ResultBuilder() {
                }

                public static ResultBuilder aResult() {
                        return new ResultBuilder();
                }

                public ResultBuilder withCode(int code) {
                        this.code = code;
                        return this;
                }

                public ResultBuilder withMessage(String message) {
                        this.message = message;
                        return this;
                }

                public ResultBuilder withData(Object data) {
                        this.data = data;
                        return this;
                }

                public Result build() {
                        Result result = new Result();
                        result.setCode(code);
                        result.setMessage(message);
                        result.setData(data);
                        return result;
                }
        }
}
